<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
if($_RQ['op']=='main'){
		$return['pluginset']=$basic=$this->plugin_setting('setting');
		$return['sharedata']=array(
			'title'=>$basic['share_title']?$basic['share_title']:'全网论坛',
			'desc'=>$basic['share_desc'],
			'link'=>custom_url('jy_sns/index/',true),
			'imgUrl'=>ATTACHMENT_URL.$basic['share_icon'],
		);
		$return['advs'] = pdo_getall('jy_sns_adv',array('uniacid'=>$_SESSION['uniacid']));	
		$return['category'] = pdo_getall('jy_sns_category',array('uniacid'=>$_SESSION['uniacid'],'isrecommand'=>1,'enabled'=>1),'','','displayorder desc');
		foreach ($return['category'] as &$cv){
			$cv['url']=$cv['url']?:'/board.lists/cate/page=1&cid='.$cv['id'];
		}
		$return['categorycount']=count($return['category']);
		$recommands = pdo_getall('jy_sns_board',array('uniacid'=>$_SESSION['uniacid'],'isrecommand'=>1,'enabled'=>1));
		if($recommands){
			foreach ($recommands as &$row ) 
			{
				$row['postcount'] =pdo_count('jy_sns_post',array('bid'=>$row['id'],'deleted'=>0,'pid'=>0));
				$row['followcount'] = pdo_count('jy_sns_board_follow',array('bid'=>$row['id']));
			}
		}
		$return['recommands']=$recommands;
		$return['params']=array('order'=>'tuijie');
		set_html('title',$basic['title']?:'论坛首页');
		exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('deleted'=>0,'pid'=>0,'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['order']=='tuijie'){
		$params['isboardbest']=1;
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
	}
	if($_RQ['bid']){
		$params['bid']=intval($_RQ['bid']);
		$isManager = isManager($_RQ['bid']);
		$isSuperManager = isSuperManager();
		if (!($isManager) && !($isSuperManager)){
			$params['checked']=1;		
		}
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_sns_post',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	foreach($list as &$row){
			$row['avatar'] = getAvatar($row['avatar']);
			$row['createtime'] = timeBefore($row['createtime']);
			$row['goodcount'] = pdo_count('jy_sns_like',array('pid'=>$row['id']));
			$row['postcount'] = pdo_count('jy_sns_post',array('pid'=>$row['id'],'deleted'=>0));
			$row['content'] = htmlspecialchars_decode($row['content']);
			$images = array();
			$rowimages = json_decode($row['images'],true);
			if (is_array($rowimages) && !(empty($rowimages))) 
			{
				foreach ($rowimages as $img ) 
				{
					if (count($images) <= 2) 
					{
						$images[] = tomedia($img);
					}
				}
			}
			$row['images'] = $images;
			$row['imagewidth'] = '100%';
			$row['imagecount'] = count($rowimages);
			if (count($row['images']) == 2) 
			{
				$row['imagewidth'] = '50%';
			}
			else if (count($row['images']) == 3) 
			{
				$row['imagewidth'] = '33%';
			}
			$row['content'] = replaceContent($row['content']);
	}
	$return['list']=$list;
	exi($return);
}
?>